/**
 * Picasa selector - a TinyMCE picasa image selector plugin
 * picasa/js/picasa.js
 *
 * This is not free software
 *
 * Plugin info: http://www.cfconsultancy.nl/
 * Author: Ceasar Feijen
 *
 * Version: 1.1 released 07/10/2013
 */
// Set options
$(function() {
	
	$('select').focus(function(){
 		  $(this).removeAttr('placeholder');
	});
	
	$('#settype').on('change', function() {
   var val= this.value;
   if(val==1){
	  	 $('#embed').attr("placeholder","Hình ảnh có dạng \nhttp://1.bp.blogspot.com/-mWMuIZ1JPCE/VH6MF19VgqI/s0/tt8-BANNER.jpg\nhttp://2.bp.blogspot.com/PRk5lXNQ0fc/s0/tt8-banner.png\nhttp://3.bp.blogspot.com/-nmAwU46qDC0/9dMNx3oOfus/s0/manga24h1.jpg\nhttp://3.bp.blogspot.com/-YxfZ3NOd_68/VH6MJ-r_M3I/s0/manga24h image naruto.jpg\n");
	   }
	if(val==2){
	  	 $('#embed').attr("placeholder",'Hình ảnh có dạng \n<img src="http://1.bp.blogspot.com/-mWMuIZ1JPCE/VH6MF19VgqI/s0/manga24h-BANNER.jpg">\n<img src="http://2.bp.blogspot.com/PRk5lXNQ0fc/s0/manga24h-banner.png">\n<img src="http://3.bp.blogspot.com/-nmAwU46qDC0/9dMNx3oOfus/s0/naruto.jpg">\n<img src="http://3.bp.blogspot.com/-YxfZ3NOd_68/VH6MJ-r_M3I/s0/dormone.jpg">');
	   }	
	   
	   
	if(val==3){
	  	 $('#embed').attr("placeholder",'Hình ảnh có dạng \n[IMG]http://1.bp.blogspot.com/-mWMuIZ1JPCE/VH6MF19VgqI/s0/0.jpg[/IMG]\n[IMG]http://2.bp.blogspot.com/PRk5lXNQ0fc/s0/tt8-banner.png[/IMG]\n[IMG]http://3.bp.blogspot.com/-nmAwU46qDC0/9dMNx3oOfus/s0/2.jpg[/IMG]\n[IMG]http://3.bp.blogspot.com/-YxfZ3NOd_68/VH6MJ-r_M3I/s0/3.jpg[/IMG]\n[IMG]http://1.bp.blogspot.com/-zqhmgZyLAmE/iWXZG0E2C3Y/s0/4.jpg[/IMG]');
	   }	   
	   
	   
});
});
 
function I_Close() {
    parent.tinymce.activeEditor.windowManager.close();
}

function convertQuotes(string){
    return string.replace(/["']/g, "");
}

function I_Insert2() {
   var dom = $('textarea#embed').val();
   var type=$( "#settype" ).val();
   if(type==0){ alert("Xin vui lòng chọn định dạng hình ảnh "); return false;}
   
   var val=$("#embed").val();
   if(val.length === 0 ){alert('Xin vui lòng past link hình ảnh'); return false; }
   
   if(type==1){
				var vals = val.match(/[^\r\n]+/g); 
				var length = vals.length;
			 	 var images='';
			  	for (var n = 0; n < length; n++) {
					images+="<img src='"+vals[n]+"' /><Br/>";
					
			 	 }
			
			 
			
   }
   
    if(type==2){
	
   		var images=val;
			
			 
			
   }
   
    if(type==3){
		val=val.replace(/\[img\]/ig,"<img src='");
		val=val.replace(/\[\/img\]/ig,"' />");
   		var images=val;
			
			 
			
   }
   
 //  alert(dom);
   // alert();
   parent.tinymce.activeEditor.insertContent(images);
   I_Close();
}
